package ru.ksu.ktk.diploma.sdi.util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TextUtil {
    private static Map<String, String> lang2Regex = new HashMap<String, String>();

    static{
        lang2Regex.put("ru", "[а-яА-Я]+");
    }

    private TextUtil() {
    }

    public static boolean isText(String input, String language) {
        if (input == null) throw new IllegalArgumentException("input cannot be null");
        if (language == null) throw new IllegalArgumentException("language cannot be null");
        if (input.length() == 0) return false;
        String regex = lang2Regex.get(language);
        if (regex == null)
            throw new IllegalArgumentException(String.format("language is not supported: %s", language.toString()));
        Matcher matcher = Pattern.compile(regex).matcher(input);

        return matcher.find();
    }

}
